/** CS2340 Spring 2011 Project
 *  Team: 40 Jiggawatt Hard Driver
 *  Suk Hwan Hong
 *  Rhys Saraceni
 *  Travis Cooper
 *  Luke Stubb
 *
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0 
 */

package edu.gatech.jiggawatt.office.gui;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import edu.gatech.jiggawatt.office.model.Patient;
import edu.gatech.jiggawatt.office.model.TreatmentRecord;
import edu.gatech.jiggawatt.office.presenter.Presenter;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * Represents "View Invoice Frame"
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0
 *
 */
public class ViewInvoiceFrame extends JFrame { // $codepro.audit.disable declareDefaultConstructors

	private JPanel contentPane;
	private JTextField patientField;
	private JTextField dateField;
	private JTextField doctorField;
	private JTextField totalAmountField;
	private String userId;
	private Presenter presenter;
	
	/**
	 * Create the frame.
	 * @param p presenter
	 * @param id id of patient
	 * @param tr treatment record to which this invoice belongs
	 */
	public ViewInvoiceFrame(Presenter p, String id, TreatmentRecord tr)
	{
		presenter = p;
		userId = id;
		Patient patient = (Patient) presenter.getUser(id);
		
		setTitle("View Invoice"); // $codepro.audit.disable stringLiterals
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 362, 490); // $codepro.audit.disable numericLiterals
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); // $codepro.audit.disable numericLiterals
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblPatientName = new JLabel("Patient Name:"); // $codepro.audit.disable stringLiterals
		lblPatientName.setBounds(28, 28, 82, 14); // $codepro.audit.disable numericLiterals
		contentPane.add(lblPatientName);
		
		patientField = new JTextField();
		patientField.setEnabled(false);
		patientField.setEditable(false);
		patientField.setBounds(130, 25, 185, 20); // $codepro.audit.disable numericLiterals
		contentPane.add(patientField);
		patientField.setColumns(10); // $codepro.audit.disable numericLiterals
		patientField.setText(patient.getFullName());
		
		JLabel lblDateOfVisit = new JLabel("Date of visit:"); // $codepro.audit.disable stringLiterals
		lblDateOfVisit.setBounds(28, 61, 82, 14); // $codepro.audit.disable numericLiterals
		contentPane.add(lblDateOfVisit);
		
		dateField = new JTextField();
		dateField.setEnabled(false);
		dateField.setEditable(false);
		dateField.setBounds(130, 56, 185, 20); // $codepro.audit.disable numericLiterals
		contentPane.add(dateField);
		dateField.setColumns(10); // $codepro.audit.disable numericLiterals
		dateField.setText(tr.getDate().toString());
		
		JLabel lblTreatingDoctor = new JLabel("Treating Doctor:"); // $codepro.audit.disable stringLiterals
		lblTreatingDoctor.setBounds(28, 95, 82, 14); // $codepro.audit.disable numericLiterals
		contentPane.add(lblTreatingDoctor);
		
		doctorField = new JTextField();
		doctorField.setEnabled(false);
		doctorField.setEditable(false);
		doctorField.setBounds(130, 92, 185, 20); // $codepro.audit.disable numericLiterals
		contentPane.add(doctorField);
		doctorField.setColumns(10); // $codepro.audit.disable numericLiterals
		doctorField.setText(tr.getTreatingDoctor());
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(130, 144, 185, 185); // $codepro.audit.disable numericLiterals
		contentPane.add(scrollPane);
		
		JTextArea billsArea = new JTextArea();
		billsArea.setEnabled(false);
		billsArea.setEditable(false);
		scrollPane.setViewportView(billsArea);
		billsArea.setText(tr.getItemizedBill());
		
		JLabel lblBills = new JLabel("Bills:"); // $codepro.audit.disable stringLiterals
		lblBills.setBounds(28, 144, 46, 14); // $codepro.audit.disable numericLiterals
		contentPane.add(lblBills);
		
		JLabel lblTotalAmount = new JLabel("Total Amount:"); // $codepro.audit.disable stringLiterals
		lblTotalAmount.setBounds(28, 351, 82, 14);
		contentPane.add(lblTotalAmount);
		
		totalAmountField = new JTextField();
		totalAmountField.setEditable(false);
		totalAmountField.setEnabled(false);
		totalAmountField.setBounds(130, 348, 185, 20);
		contentPane.add(totalAmountField);
		totalAmountField.setColumns(10);
		totalAmountField.setText("$" + tr.calculateTotal());
		
		JButton btnBack = new JButton("Back"); // $codepro.audit.disable stringLiterals
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
				dispose();
			}
		});
		btnBack.setBounds(130, 405, 89, 23);
		contentPane.add(btnBack);
	}
}
